package com.lhd.egmvc1.controller;

import com.lhd.egmvc1.mapper.AddressMapper;
import com.lhd.egmvc1.pojo.entity.Address;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author lhd
 * @date 2024/4/23
 * @apiNote
 */
@RestController
@RequestMapping("/address/")
public class AddressController {
    @Autowired
    private AddressMapper addressMapper;
    /**
     * 1.添加收货地址
     */
    @PostMapping(value = "insert")
    public String insertAddress(Address address) {
        System.out.println("address = " + address);
        addressMapper.insert(address);
        return "添加成功";
    }

    /**
     * 2.查询收货地址
     */
    @GetMapping(value = "selectAll")
    public List<Address> selectAddress(Address address) {
        System.out.println("address = " + address);
        return addressMapper.selectAll();
    }

    /**
     * 3.删除收货地址
     */
    @PostMapping(value = "delete")
    public String deleteAddressById(int id) {
        addressMapper.deleteById(id);
        return "删除成功";
    }
    /**
     * 4.修改收货地址
     */
    @PostMapping(value = "update")
    public String updateAddress(Address address) {
        System.out.println("address = " + address);
        addressMapper.update(address);
        return "修改成功";
    }

}
